echo  "Detecting ethernet interfaces on this device. . ."

# Get a list of wireless interfaces and create and array out of their names

IFACES=`iwconfig 2>&1 | grep "no wireless" | awk '{print $1}'`
IFACES_STRING=`echo $IFACES`
IFS=" "
IFACES_ARR=( $IFACES_STRING )

# Loop through every wireless interface name

j=1
for ((i=0; i<${#IFACES_ARR[@]}; i++))

do
#        Find the MAC address of the current interface

        GET_IFACE=${IFACES_ARR[$i]}
        GET_MAC=`ifconfig $GET_IFACE | grep "HWaddr" | awk '{print $5}'`

        STRCMP=`echo $GET_MAC`

        # Implement a hardware listener to get the driver detils of that interface

        if [ -n "$STRCMP" ]; then
        
                DRIVER_NAME=`lshw -C network | grep -B 7 $GET_MAC | grep "product"`
                VEND_NAME=`lshw -C network | grep -B 7 $GET_MAC | grep "vendor"`

                if [ -n "$DRIVER_NAME" ]
                then
                        if [ -n "$VEND_NAME" ]
                        then
                                echo  "Ethernet Detected! - "$GET_IFACE" - "${VEND_NAME:15}" "${DRIVER_NAME:16}""
				echo "timeout 2 ;" >> /etc/dhcp3/dhclient.conf
				ifconfig $GET_IFACE up
				dhclient $GET_IFACE 
				
                                IFACE_STATUS=`ifconfig $GET_IFACE | grep "inet addr"`

				if [ -n "$IFACE_STATUS" ]; then
					echo "$GET_IFACE is alive!"
					echo "IS_GW yes $GET_IFACE" > config/gw_setup.conf
					echo "WAN_IF $GET_IFACE" > config/wan_setup.conf
					break
				else
					echo "$GET_IFACE is not alive!"
					echo "IS_GW no" > config/gw_setup.conf
					echo "" > config/wan_setup.conf
				fi
			fi
                fi
        fi
done

